package shuiyuqing.network;

import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.HttpHeaderParser;
import com.android.volley.toolbox.StringRequest;
import com.google.gson.Gson;
import com.whu.administrator.ws.MyApplication;
import com.whu.administrator.ws.R;
import com.whu.administrator.ws.VolleySingleton;

import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import inter.Delegate;
import shuiyuqing.dto.DATA;

/**
 * 获取历史
 * Created by Administrator on 2016/3/22.
 */
public class GetHistoryHydInfo {
    Delegate delegate;
    StringRequest stringRequest;

    SearchHisData searchHisData;

    public void setSearchHisData(SearchHisData searchHisData) {
        this.searchHisData = searchHisData;
    }

    public void setDelegate(Delegate delegate) {
        this.delegate = delegate;
    }

    public void get() {
        String ip = MyApplication.share().getResources().getString(R.string.IP);
        String url = "http://"+ip+"/WaterInfo/GetHistoryHydInfo";
        stringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String response) {
                Log.i("历史水情信息", response);
                if (delegate != null)
                    delegate.onResponse(response);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                if (delegate != null)
                    delegate.onErrorResponse(error);
            }
        }){

            @Override
            protected Map<String, String> getParams() {
                Map map = new HashMap();
                Gson gson = new Gson();
                map.put("data", gson.toJson(searchHisData));
                return map;
            }
            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {
                String temp = null;
                try {
                    temp = new String(response.data, "utf-8");
                } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();
                }
                return Response.success(temp, HttpHeaderParser.parseCacheHeaders(response));
            }
        };
        VolleySingleton.getVolleySingleton(MyApplication.share()).addToRequestQueue(stringRequest);
    }

    public void cancel()
    {
        if (!stringRequest.isCanceled())
            stringRequest.cancel();
    }

    public static class SearchHisData {
        private String st_ID;
        private String date;

        public String getSt_ID() {
            return st_ID;
        }
        public void setSt_ID(String st_ID) {
            this.st_ID = st_ID;
        }
        public String getDate() {
            return date;
        }
        public void setDate(String date) {
            this.date = date;
        }
    }

    public static class RTData {
        private Double STID;			// 站点编号
        private String SURVEYTIME;		// 测报时间
        private Double DAYRAINFALL;		// 日降雨量
        private Double SUMRAINFALL;		// 累积降雨量
        private Double WATERLEVEL;		// 水位
        private Double VOLTAGE;			// 电压
        private Double CAPACITY;		// 容量
        private Double FLOW;			// 流量


        public Double getSTID() {
            return STID;
        }
        public void setSTID(Double sTID) {
            STID = sTID;
        }
        public String getSURVEYTIME() {
            return SURVEYTIME;
        }
        public void setSURVEYTIME(String sURVEYTIME) {
            SURVEYTIME = sURVEYTIME;
        }

        public Double getDAYRAINFALL() {
            return DAYRAINFALL;
        }
        public void setDAYRAINFALL(Double dAYRAINFALL) {
            DAYRAINFALL = dAYRAINFALL;
        }
        public Double getSUMRAINFALL() {
            return SUMRAINFALL;
        }
        public void setSUMRAINFALL(Double sUMRAINFALL) {
            SUMRAINFALL = sUMRAINFALL;
        }
        public Double getWATERLEVEL() {
            return WATERLEVEL;
        }
        public void setWATERLEVEL(Double wATERLEVEL) {
            WATERLEVEL = wATERLEVEL;
        }
        public Double getVOLTAGE() {
            return VOLTAGE;
        }
        public void setVOLTAGE(Double vOLTAGE) {
            VOLTAGE = vOLTAGE;
        }
        public Double getCAPACITY() {
            return CAPACITY;
        }
        public void setCAPACITY(Double cAPACITY) {
            CAPACITY = cAPACITY;
        }
        public Double getFLOW() {
            return FLOW;
        }
        public void setFLOW(Double fLOW) {
            FLOW = fLOW;
        }

    }

    public static class ResponseHisHydInfo {
        private String status;
        private List<RTData> hisData;

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public List<RTData> getHisData() {
            return hisData;
        }

        public void setHisData(List<RTData> hisData) {
            this.hisData = hisData;
        }

    }


}
